<template>
  <div class="activity-management">
    <h1>活动管理</h1>
    <button class="add-btn" @click="addActivity">添加活动</button>
    <ul class="activity-list">
      <li v-for="activity in activities" :key="activity.id" class="activity-item">
        <h3>{{ activity.title }}</h3>
        <p>{{ activity.date }} - {{ activity.location }}</p>
        <button class="delete-btn" @click="deleteActivity(activity.id)">删除</button>
      </li>
    </ul>
  </div>
</template>

<script>
import activities from '@/assets/activities.json'

export default {
  data() {
    return {
      activities
    }
  },
  methods: {
    addActivity() {
      // 实现添加活动逻辑
    },
    editActivity(activity) {
      // 实现编辑活动逻辑
    },
    deleteActivity(id) {
      // 实现删除活动逻辑
    }
  },
  beforeRouteEnter(to, from, next) {
    const isAdmin = localStorage.getItem('isAdmin') === 'true'
    if (!isAdmin) {
      alert('无权限访问该页面')
      next({ name: 'home' })
    } else {
      next()
    }
  }
}
</script>

<style scoped>
.activity-management {
  max-width: 800px;
  margin: 2rem auto;
  padding: 1rem;
}

.add-btn {
  background-color: #42b983;
  color: white;
  border: none;
  padding: 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: background-color 0.3s;
  margin-bottom: 1rem;
}

.add-btn:hover {
  background-color: #348c66;
}

.activity-list {
  list-style: none;
  padding: 0;
}

.activity-item {
  background-color: #f9f9f9;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  margin-bottom: 1rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.activity-item h3 {
  margin-top: 0;
  color: #42b983;
}

.activity-item p {
  margin-bottom: 0.5rem;
  color: #666;
}

.delete-btn {
  background-color: #e74c3c;
  color: white;
  border: none;
  padding: 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background-color 0.3s;
}

.delete-btn:hover {
  background-color: #c0392b;
}
</style>